﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EislaufScb.Model.Repository;
using EislaufScb.Model;

namespace EislaufScb.WebForms.ViewModel.News
{
    public class NewsHomeViewModel
    {
        public string Title { get; set; }

        public string Content { get; set; }

        public string PublishingDate { get; set; }

        public NewsHomeViewModel() : base()
        {
            
        }

        public static List<NewsHomeViewModel> GetNews()
        {
            List<NewsHomeViewModel> result = new List<NewsHomeViewModel>();
            
            using (BaseRepository repository = new BaseRepository(new ClubModelContainer()))
            {
                repository.GetAll<BlogEntry>().Where(blog => blog.Blog.Name.Equals("News")).ToList().ForEach(entry => result.Add(new NewsHomeViewModel() { Title = entry.Title, Content = entry.Content, PublishingDate = entry.PublishingDate.ToShortDateString() }));
            }

            return result;
        }
    }
}
